package com.dsshare.util;

import org.springframework.beans.factory.annotation.Value;

import java.util.Date;
import static org.apache.commons.lang.math.RandomUtils.nextInt;

/**
 * Created by Simon on 2018/2/2.
 * Description: ...
 */
public class SignUtil {
    /*no use*/
    static String publicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAo1rCytvK/SzvOe9RsEKYWUyoBwEgckb3ACtpFRTN5w6xJqdGV93/2LUHjHhMMfy9L1XZGldF/MIZXvcl/RePH2uILvorK/UD2KwviuBuHKdbYicoWi1ge32t77+koaQDuTFdSjww7ke9WY/YK65JciCX+ivyjefT103+6/aJl3yZc2nrOGmEB6Lyi07Rq28leC1RlwAaBnz9TyhDTq25mOsLH0LZZfPkL/xVrvhxeNCDp6MM/LKJo049Kjv5T+C29vmXQPtJDd4toZYzY4VWLHqktFPg85suuYzyMD2vOe+0AAodNl5/zW83Fq2xZiVyDHMAjTmhBGpbiwWNKYeluQIDAQAB";
    /**
     * privateKey 加密
     * @param source
     * @return
     * @throws Exception
     */
    public static String privateKeySign(String source,String privateKey) throws Exception {
        System.out.println("\r加密前：\r\n" + source);
        String sign = RSAUtils.sign(source.getBytes("UTF-8"), privateKey);
        System.out.println("加密后：\r\n" + sign);
        return sign;
    }

    /**
     * PublicKey 解密
     * @param encryptedData
     * @throws Exception
     */
    public static void decryptByPublicKey(byte[] encryptedData) throws Exception {
        RSAUtils.decryptByPublicKey(encryptedData,publicKey);
    }


    /*public static void main(String[] arg) {
        String chanelId = "2019";
        int random = nextInt();
        long times = new Date().getTime();
        String data = chanelId + ";" + random + ";" +times;
        try {
            sign(data);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/

}
